package com.crm.base.controller;

import com.crm.base.service.StorageService;
import com.crm.common.pojo.Storage;
import com.crm.global.exception.ExceptionEnum;
import com.crm.global.result.Message;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "库存信息")
@RequestMapping("/storage")
public class StorageController {

    @Autowired
    private StorageService storageService;

    @ApiOperation(value = "查询所有的库存",notes = "根据条件(仓库或者产品名称)查询")
    @PostMapping("/findAll")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name = "page",defaultValue = "1",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(value = "页面大小",name = "size",defaultValue = "1",required = true,dataType = "int",paramType = "query")
    })
    public ResponseEntity<Message<PageInfo<Storage>>> findAll(int page, int size, @RequestBody(required = false) Storage storage) {
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS,storageService.findAll(page,size,storage)));
    }
}
